home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / tp_xmn.arc / EXAMINE.DOC next >
Text File  |  1991-04-28  |  18KB  |  491 lines

  1.  
  2.   EXAMINE          Assembly Level Examination Utility          Version 2 ß
  3.  
  4.                 Copyright (c) 1989   Richard W. Prescott
  5.                           All Rights Reserved
  6.  
  7.  
  8.  All brand and product names mentioned herein are trademarks or registered 
  9.                 trademarks of their respective holders.
  10.  
  11.   ┌─────────────────────────────────────────────────────────────────────┐
  12.   │  This file contains documentation for the program file EXAMINE.EXE  │
  13.   └─────────────────────────────────────────────────────────────────────┘
  14.  
  15.  
  16. The following topics are described below:
  17.  
  18. 1. Overview
  19. 2. Command line options
  20. 3. Producing a Map file
  21. 4. Behind EXAMINE.EXE
  22. 5. System Requirements
  23. 6. DISCLAIMER
  24. 7. Purchase Information
  25. 8. TP&Asm/TP&Asm-M
  26.  
  27.  
  28.  
  29.  
  30. 1. Overview
  31.  
  32. EXAMINE.EXE is a utility program which can be used to display the 
  33. assembly level implementation for each line of any source files 
  34. compiled with Turbo Pascal version 4.0 or 5.0.  You must compile to 
  35. disk, and you must instruct the compiler to create a map file with 
  36. line number detail, as explained below.  
  37.  
  38. The default presentation is to the screen, however output may be
  39. redirected to the printer (>PRN) or to a file (>filename.ext).
  40.  
  41. The following presents a section of EXAMINE output:
  42.  
  43.  
  44. ----
  45.   m := 0;                                          ─── Source Line
  46.                                                    ┐   
  47. 4FB0:0075 31C0          XOR     AX,AX              ├── Corresponding
  48. 4FB0:0077 8946BA        MOV     [BP-46],AX         ┘    disassembly
  49. ----                                            
  50.   FOR n := 0 TO SearchLimit DO BEGIN               ─── Source Line
  51.                                                    ┐
  52. 4FB0:007A 8B4608        MOV     AX,[BP+08]         │
  53. 4FB0:007D 8946B8        MOV     [BP-48],AX         │
  54. 4FB0:0080 31C0          XOR     AX,AX              │   Corresponding
  55. 4FB0:0082 3B46B8        CMP     AX,[BP-48]         ├──   DEBUG.COM 
  56. 4FB0:0085 7F5B          JG      00E2               │    disassembly
  57. 4FB0:0087 8946BC        MOV     [BP-44],AX         │
  58. 4FB0:008A EB03          JMP     008F               │
  59. 4FB0:008C FF46BC        INC     WORD PTR [BP-44]   ┘
  60. ----
  61.     IF FindArray[n] = FindStr[1] THEN BEGIN        ─── Source Line
  62.                                                    ┐
  63. 4FB0:008F 8B46BC        MOV     AX,[BP-44]         │
  64. 4FB0:0092 C47E0A        LES     DI,[BP+0A]         │   Corresponding
  65. 4FB0:0095 03F8          ADD     DI,AX              ├──   DEBUG.COM 
  66. 4FB0:0097 26            ES:                        │    disassembly
  67. 4FB0:0098 8A05          MOV     AL,[DI]            │
  68. 4FB0:009A 3A46BF        CMP     AL,[BP-41]         │
  69. 4FB0:009D 753B          JNZ     00DA               ┘
  70. ----
  71.  
  72.  
  73.  
  74. EXAMINE.EXE is useful in a number of situations:
  75.  
  76. To simplify the designing of external PROCs.  (For example, by 
  77. writing the PROC shell first in Pascal and using EXAMINE to 
  78. determine the parameter offsets, parameter push sequence for  
  79. procedure calls, etc).  
  80.  
  81. To verify the assembly code produced by my Integrated Compile-time 
  82. Assembler TP&Asm.  (This is the reason why Examine was written).  
  83.  
  84. To simplify converting Pascal code to assembly language for use 
  85. within TP&Asm, or with Inline or External.  
  86.  
  87.  
  88.  
  89.  
  90. 2. Command line options
  91.  
  92. Examine may be invoked with just a single file name, or with up to 
  93. three file names, a procedure name, and starting and ending line 
  94. numbers.  The general format for invoking examine is:
  95.  
  96. Examine SourceName ExeName MapName [ProcName StartLine EndLine]
  97.  
  98. Most of the above parameters may be omitted.  The use of brackets 
  99. '[..]' is required when specifying a Proc/Function or Line Number 
  100. limit.  Omitted parameters will assume default values as specified 
  101. below:
  102.  
  103.    Default Source path = current directory
  104.    Default Source name = 'NONAME'
  105.    Default Source ext  = 'PAS'
  106.  
  107.    Default Executable path = Source path
  108.    Default Executable name = Source name
  109.    Default Executable ext  = 'EXE'
  110.  
  111.    Default Map path = Executable path
  112.    Default Map name = Executable name
  113.    Default Map ext  = 'MAP'
  114.  
  115.    Default Start Line  = 1 
  116.    Default Ending Line = End of Source File
  117.  
  118.    If only one line number is specified, it is taken to be the starting 
  119.    line.  
  120.  
  121.  
  122. Examples
  123.  
  124. To Examine all of MYPROG.PAS with MYPROG.PAS, MYPROG.EXE, and
  125. MYPROG.MAP all in the current directory:
  126.  
  127.   Examine myprog
  128.  
  129. If all three files are in the directory C:\PASFILES:
  130.  
  131.   Examine c:\pasfiles\myprog
  132.  
  133. To limit Examine to the procedure FIRSTPROC:
  134.  
  135.   Examine myprog [firstproc]
  136.  
  137. To limit Examine to a specific range of lines
  138.  
  139.   Examine myprog [56 185]
  140.  
  141. To limit Examine to a range of lines within FIRSTPROC:
  142.  
  143.   Examine myprog [firstproc 56 185]
  144.  
  145.  
  146. Examine was designed to handle Units.  Do not attempt to Examine a 
  147. TPU file, however.  Rather, a Unit may be specified as the source 
  148. file when examining an executable file which Uses that Unit:
  149.  
  150. If MyProg uses a unit MyUnit,
  151.  
  152.   Examine myunit myprog
  153.  
  154.  
  155. Examine was not intended to handle include files, however the 
  156. only real limitation is the following:  If a source file contains 
  157. executable code both before and after an include directive, then 
  158. the line number table for that source file will be split into two 
  159. pieces, and only the first piece can be examined.  The included file 
  160. (eg INCLUDE.PAS) may be examined by specifying it as the source 
  161. file: 
  162.  
  163.   Examine include myprog
  164.  
  165.  
  166. Using Output Redirection:
  167.  
  168. The LAST parameter specified on the command line may be a "greater 
  169. than" symbol > , followed by "PRN" or the name of a file.  This 
  170. instructs the operating system to redirect standard output from the 
  171. screen to the printer (PRN) or the named file.  EXAMINE.EXE fully 
  172. supports output redirection.
  173.  
  174. To Examine MYPROG.PAS with output sent to the printer: 
  175.  
  176.   Examine myprog >PRN
  177.  
  178. To Examine a range of lines within the Unit MyUnit, with output 
  179. saved in the file MYUNIT.XMN:
  180.  
  181.   Examine myunit myprog [56 185] >myunit.xmn
  182.  
  183.  
  184. EXAMINE detects output redirection and provides an on-screen status 
  185. report of progress through the executable file.  
  186.  
  187. The short batch file XM.BAT is provided to simplify the process of
  188. redirecting output to a disk file.  Command line parameters for XM 
  189. are the same as for EXAMINE, with the exception that the SourceName
  190. parameter for XM must omit the extension ".PAS".  The last example 
  191. above can be accomplished more simply using XM:
  192.  
  193.   XM myunit myprog [56 185]
  194.  
  195.  
  196. Please refer to your MS-DOS/PC-DOS Manual for further information on 
  197. the use of Output Redirection.
  198.  
  199.  
  200.  
  201.  
  202. 3. Producing a Map file
  203.  
  204. To produce a map file using the Turbo Version 5.0 Integrated 
  205. Development Environment: 
  206.  
  207. Be sure all units you may wish to examine are compiled in the 
  208. (default) {$D+} state.  Then set 
  209.            Options/Linker/Map file/Detailed 
  210. and compile the program file to disk.
  211.  
  212.  
  213. To produce a map file using TPC Version 5.0:
  214.  
  215. Be sure all units you may wish to examine are compiled in the 
  216. (default) {$D+} state.  Then compile with the command line option 
  217. "/gd":
  218.  
  219.   tpc myprog /gd
  220.  
  221.  
  222. To produce a map file using the Turbo Version 4.0 Integrated 
  223. Development Environment: 
  224.  
  225. Be sure all units you may wish to examine are compiled in the 
  226. (default) {$D+} state.  Then set 
  227.    Options/Compiler/Turbo pascal map file generation ... On
  228. and compile the program file to disk.  This will produce an EXE and 
  229. a TPM file.  Then use TPMAP to produce the final Map file from 
  230. myprog.tpm:
  231.  
  232.   tpmap myprog
  233.  
  234.  
  235. To produce a map file using TPC Version 4.0:
  236.  
  237. Be sure all units you may wish to examine are compiled in the 
  238. (default) {$D+} state.  Compile with the command line option "/$T+", 
  239. and then use TPMAP to produce the final Map file:
  240.  
  241.   tpc myprog /$T+
  242.   tpmap myprog
  243.  
  244.  
  245.  
  246.  
  247. 4. Behind EXAMINE.EXE
  248.  
  249. EXAMINE produces its disassembly by running DEBUG.COM from your DOS 
  250. disk as a "child process" and requesting disassembly of the required 
  251. sections via the DEBUG unassemble command "-u".  The advantage of 
  252. using DEBUG.COM rather than an internally written disassembler is 
  253. that the disassembly generated is then essentially guaranteed to be 
  254. reliable.  Users who feel comfortable with the reliability of 
  255. DEBUG.COM can be equally confident in the disassembly produced by 
  256. EXAMINE.  
  257.  
  258. In addition, this technique illustrates how to create a useful 
  259. utility from an existing program without having to "reinvent the 
  260. wheel" (or rewrite the disassembler).  
  261.  
  262. The following description provides an overview of how EXAMINE 
  263. operates:
  264.  
  265.   1. EXAMINE first verifies that it can find the Source, MAP, 
  266.      and Executable files and checks the dates of these files.
  267.      If the Source date is later than the Executable file date,
  268.      or if the MAP and Executable file dates differ by more than 
  269.      8 seconds, the user is asked to confirm before continuing.
  270.  
  271.   2. The MAP file is then read and processed.  The Line Number
  272.      Table for the specified source file is stored in compressed 
  273.      form, 4 bytes per Line Number entry.
  274.  
  275.   3. The Source file is then read and stored immediately following 
  276.      the compressed Line Number Table.
  277.  
  278.      EXAMINE uses DOS Memory Allocation techniques rather than 
  279.      using the Turbo heap to allocate space for the MAP and Source 
  280.      files.  This permits memory not required by these files to be 
  281.      reclaimed for use by DEBUG.COM and the Executable file.  (In 
  282.      contrast, the full amount "heapmax" as specified in the {$M }
  283.      compiler directive is reserved by the Turbo program and is not
  284.      available for use by a program under "Exec").
  285.  
  286.   4. EXAMINE installs a new interrupt $21 handler which replaces 
  287.      the DOS Buffered Input Function 0Ah.  EXAMINE also monitors 
  288.      Function $30 (Get DOS Version) and the undocumented Function 
  289.      $50 (Set PSP) used by DEBUG.COM.  All other function requests 
  290.      are passed directly to the original interrupt $21 handler.  
  291.  
  292.   5. EXAMINE Executes DEBUG.COM with the Executable file specified
  293.      as a command line parameter.  DEBUG loads into memory, loads 
  294.      the Executable file, and then waits for input via the DOS 
  295.      Buffered Input Function 0Ah.  
  296.  
  297.   6. Each time EXAMINE's Function 0Ah handler receives a request 
  298.      for input, it
  299.       1) Writes a source line or series of source lines (as 
  300.          indicated by the MAP file Line Number Table) to the 
  301.          standard output device.
  302.       2) Returns to DEBUG.COM with an unassemble command which
  303.          instructs DEBUG to display (to the standard output device)
  304.          the disassembly of the source line(s) just displayed.
  305.  
  306.   7. The process in (6.) repeats until EXAMINE instructs DEBUG to
  307.      display the disassembly of the final source line requested.
  308.      On the NEXT Function 0Ah input request, EXAMINE instructs 
  309.      DEBUG.COM to exit with a quit "-q" request, and the EXEC 
  310.      process terminates.
  311.  
  312.   8. On return from the EXEC process, EXAMINE restores the original
  313.      interrupt $21 handler, and exits to DOS.
  314.  
  315.  
  316.  
  317.  
  318. 5. System Requirements
  319.  
  320. Examine Version 2 ß requires: DEBUG.COM running on an IBM PC or 
  321. Compatible, with Version 2.0 or above of MS-DOS or PC-DOS.  
  322. Minimum memory requirements are 128K plus memory required by the 
  323. executable program being examined.
  324.  
  325.  
  326. Limitations and other notes:
  327.  
  328. Source and Map files are limited to 64K bytes.  Executable file size 
  329. is not limited, but must be small enough to load into memory after 
  330. Examine's minimum memory requirement of 128K.
  331.  
  332. If Examine cannot find one of the files you specify, it will report 
  333. the full path specification it was using for the file it failed to 
  334. find.
  335.  
  336. If Examine encounters an error with the Map file, it will tell you.  
  337. Make sure the file you specify is an UNMODIFIED Map file, with full 
  338. line number detail, produced by Turbo/TPC Version 5.0 or by TPMAP 
  339. Version 4.0.
  340.  
  341. Examine attempts to recognize string constants and display them in
  342. a readable DB format, for example:  DB 11,'Hello World'
  343. If Examine fails to recognize a string constant, the fallback 
  344. presentation uses the standard DEBUG.COM disassembly.
  345.  
  346. Examine will attempt to exit gracefully when it detects the output
  347. disk becoming full (under output redirection).  If it detects fewer
  348. than 5 free "clusters" (approximately 4K free on a floppy), it will
  349. exit with the message "Insufficient space on output disk".  Replace
  350. or otherwise correct the disk problem, and re-execute Examine.
  351.  
  352.  
  353.  
  354.  
  355. 6. DISCLAIMER OF WARRANTY 
  356.  
  357. This software and accompanying documentation are sold "as is" and 
  358. without warranties as to performance or merchantability.  
  359.  
  360. This program is sold without any express or implied warranties 
  361. whatsoever.  Because of the diversity of conditions and hardware 
  362. under which this program may be used, no warranty of fitness for a 
  363. particular purpose is offered.  The user is advised to test the 
  364. program thoroughly before relying on it.  THE USER MUST ASSUME THE 
  365. ENTIRE RISK OF USING THE PROGRAM.  ANY LIABILITY OF THE AUTHOR WILL 
  366. BE LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF THE 
  367. PURCHASE PRICE.  
  368.  
  369.  
  370.  
  371.  
  372. 7. Purchase Information.
  373.  
  374. Note: Registered users of TP&Asm (described below) are automatically 
  375. registered users of EXAMINE.  The EXAMINE.EXE program file is 
  376. currently included on the TP&Asm registration disk.  Source code for 
  377. EXAMINE.EXE will be included on registration and update disks 
  378. beginning with TP&Asm Version 2.0.  
  379.  
  380. The EXAMINE package is distributed as shareware.  After you have 
  381. reviewed the package for a reasonable period of time (say, 30 days), 
  382. please register it or purchase TP&Asm if you plan to continue using 
  383. it.  As a benefit of registration, you can receive full source code 
  384. for the program file EXAMINE.EXE.  (Available approximately April 
  385. 15, 1989).
  386.  
  387. Even if you choose not to register, I encourage you to retain a copy 
  388. of EXAMINE and distribute it to others via BBS or on diskette.  
  389. Please include all files in the distribution package.  
  390.  
  391. The following price list applies to registration of EXAMINE and 
  392. purchase of TP&Asm.  Users who choose to register EXAMINE with the 
  393. "registration + disk" option will receive an update disk, including 
  394. source code, by about April 15, 1989.  Users who register EXAMINE 
  395. with the "registration only" option do not receive source code but 
  396. may elect to do so at a later date by sending the additional $3 P&H.  
  397.  
  398.  
  399. EXAMINE Registration   ... $15 + $3 P&H for registration + disk
  400.                            $15  (total) for registration only
  401.  
  402. TP&Asm Version 2.0     ... $49 + $3 P&H (not yet available)
  403.  
  404. TP&Asm Version 2 ß     ... $39 + $3 P&H including free upgrade
  405.                                           to Version 2.0.
  406.  
  407. (Wisconsin residents, please add 5% sales tax).
  408.  
  409. All prices listed are for standard 5 1/4 inch floppy disks.  Add
  410. $2 for distribution on 3 1/2 inch disks.
  411.  
  412.  
  413. Please send a check or money order payable to:
  414.  
  415.                       Richard W. Prescott
  416.                       724 Sauk Ridge Trail
  417.                       Madison, WI  53705
  418.  
  419.  
  420. When purchasing TP&Asm, please include the following information:
  421.  
  422.   1. Full Version number of the Turbo Pascal compiler you now use.
  423.  
  424.   2. Your registration number for that compiler.
  425.  
  426.   3. If you obtained TP&Asm-M from a bulletin board:
  427.      3a. Area code and phone number of that bulletin board
  428.      3b. Full Version number of the TP&Asm-M version you have
  429.      3c. Directory Date of the README file
  430.  
  431.  
  432.  
  433.  
  434. 8. TP&Asm/TP&Asm-M
  435.  
  436. TP&Asm is a small assembler which runs Turbo 4.0/5.0 (Integrated
  437. Environment or TPC) as a subprocess and permits you to place 
  438. assembly language statements directly into your Pascal source code 
  439. in blocks beginning with the keywords "Assemble" and/or "Internal".  
  440.  
  441. TP&Asm provides the convenience and flexibility of having "live" 
  442. assembly language in your programs which can be modified and 
  443. immediately recompiled with no need to exit and reassemble.  You 
  444. have complete freedom to place assembly language anywhere in your 
  445. program, freely mix Pascal and assembly blocks, freely transfer 
  446. between Pascal and assembly blocks via Call/Jump/Loop/Goto to any 
  447. Pascal or assembly label, make direct Call, Jmp and Offset 
  448. references to Pascal Proc/Functions, and make simplified Pascal 
  449. style references to your Pascal and assembly variables and 
  450. parameters.  Units compiled with TP&Asm can be distributed and 
  451. Used independent of TP&Asm.  
  452.  
  453. With Turbo Version 5.0, you can trace your assembly code line by 
  454. line in the IDE.  Using the record variable CPU defined in the unit 
  455. ASMWATCH (included), you can Watch, Evaluate, and Modify the CPU 
  456. registers and flags during the trace.  
  457.  
  458. The result is an ASSEMBLY Development Environment which is identical 
  459. to your PASCAL Development Environment.  It provides fast assembly 
  460. with no additional disk access, and reports assembly syntax errors 
  461. on the standard Turbo error line with cursor placed on the error.  
  462. It accepts the standard syntax of both MASM and A86, but also 
  463. provides certain enhancements such as the placement of named data 
  464. in the Code Segment.  
  465.  
  466. TP&Asm can be purchased as described in the preceding section.
  467.  
  468. A shareable Memory Mode version called TP&Asm-M is also available.  
  469. The distinction between TP&Asm and TP&Asm-M is that TP&Asm-M is 
  470. intended for developing and debugging assembly language in the IDE, 
  471. but not for final compilation.  You can compile to Memory (with the 
  472. standard Turbo style interactive syntax error detection) and Trace 
  473. your assembly code in the IDE with full capability to Watch, 
  474. Evaluate, and Modify the CPU registers and Flags - then convert to 
  475. INLINE or EXTERNAL after the code is fully developed.  TP&Asm-M's 
  476. INTERNAL statement and its support of the standard syntax of MASM, 
  477. A86, and INLINE.COM simplifies this conversion.  
  478.  
  479. The TP&Asm-M distribution disk can be ordered from me for $5 plus 
  480. $3 P&H, with the $5 being credited toward subsequent registration 
  481. of TP&Asm or TP&Asm-M.  It can also be downloaded from the IBMPRO 
  482. or BPROGA forums on CompUServe.  Look for TPA2-A.ARC and TPA2-R.ARC.
  483. Registration for TP&Asm-M is $19.
  484.  
  485.  
  486.  
  487.  
  488.  
  489. EXAMINE.EXE was compiled and assembled using TP&Asm Version 2 ß 
  490. running Turbo Pascal Version 5.0.  
  491.